import 'package:flutter/material.dart';
import 'package:love_app/common/su.dart';
import 'package:love_app/providers/search_provider.dart';
import 'package:love_app/providers/share_provider.dart';
import 'package:provider/provider.dart';

import 'search_ui/search_data.dart';

// 社区收拾页面
class CommunitySearch extends SearchDelegate<String> {

  SearchProvider searchProvider;
  ShareProvider shareProvider;
  @override
  ThemeData appBarTheme(BuildContext context) {
    // 搜索框主题颜色
    shareProvider = Provider.of<ShareProvider>(context, listen: false);
    searchProvider = Provider.of<SearchProvider>(context, listen: false);
    return ThemeData(
      primaryColor: shareProvider.textColor,
      primaryIconTheme: IconThemeData(
        color: Colors.black,
      ),
    );
  }

  @override
  List<Widget> buildActions(BuildContext context) {
    //清空按钮
    return [
      IconButton(
        icon: Icon(Icons.clear),
        onPressed: (){
          if(query.length > 0){
            query = "";
          }else{
            close(context, null);
          }
        }, //搜索值为空
      )
    ]; 
  }

  @override
  Widget buildLeading(BuildContext context) {
    //返回上级按钮
    return IconButton(
      icon: AnimatedIcon(
        icon: AnimatedIcons.menu_arrow, progress: transitionAnimation
      ),
      onPressed: (){
        searchProvider.clean();
        Su.suPrints("触发");
        close(context, null);
      }  //点击时关闭整个搜索页面
    );
  }

  @override
  Widget buildResults(BuildContext context) {
    searchProvider.clean();
    return SearchData(search: query);
  }

  @override
  Widget buildSuggestions(BuildContext context) {
    //设置推荐
    return Container();
  }
}